package aar.test.tessocr.base;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics;



import java.util.Locale;

import aar.test.tessocr.utils.ConstantPara;
import aar.test.tessocr.utils.LogUtils;
import aar.test.tessocr.utils.PrefUtils;

public class BaseFragmentActivity extends FragmentActivity {
	
	AppManager appManager ;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		appManager = AppManager.getAppManager();
		// 把当前activity加入栈中
		appManager.addActivity(this);
		appManager.getSize("前堆栈activity数目");
		changeLanguage();

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		// activity关闭，从栈中移除
		appManager.finishActivity(this);
		appManager.getSize("后堆栈activity数目");
	}

	@Override
	protected void onResume() {
		super.onResume();
		changeLanguage();
	}

	private void changeLanguage() {

		String language = PrefUtils.getString(this, ConstantPara.CHANGE_LANGUAGE_PREF_KEY, "zh");

		LogUtils.e("language","language=="+language);
		// 本地语言设置
		Locale myLocale = new Locale(language);
		Resources res = getResources();
		DisplayMetrics dm = res.getDisplayMetrics();
		Configuration conf = res.getConfiguration();
		conf.locale = myLocale;
		res.updateConfiguration(conf, dm);


	}




}
